<?php defined('SYSPATH') or die('No direct script access.'); ?>
<?php echo "<?php defined('SYSPATH') or die('No direct script access.');?>" ?>

<a href="<?php echo "<?php echo URL::site('" . ($set_dir ? $dir.'/':'') . "$model/edit/" . "') ?>" ?>">New</a>
<?php echo "<?php if (count($$models) > 0):?>" ?>

<?php echo "<?php echo form::open('". ($set_dir ? $dir.'/':'') ."{$model}/action', array('id'=>'{$model}_list_form'))?>" ?>
<?php echo "<?php echo Form::hidden('action', '') ?>" ?>
<div class="list_actions">
    <input type="button" value="Delete" onclick="doAction(this, 'delete', true, 'Delete selected?');" />
</div>
<div class="block">
    <table>
        <thead>        
        <th align="center" width="10"><input id="<?php echo $model ?>_check_all" type="checkbox"></th>
        <?php foreach ($fields as $f): ?>
        <th><?php echo $f['name'] ?></th>
        <?php endforeach; ?>
        <th>Created</th>
        <th>Updated</th>
        <th></th>
        </thead>
        <tbody>
            <?php echo "<?php foreach ($$models as $$model):?>" ?>
            <tr class="<?php echo "<?php echo text::alternate('odd', 'even')?>" ?>">                
                <td width="10" align="center">
                    <input class="checkbox" name="<?php echo $model ?>_ids[]" value="<?php echo "<?php echo $" . $model . "->id ?>" ?>" type="checkbox" />
                </td>

                <?php foreach ($fields as $f): ?>
                <td><?php echo "<?php echo $" . $model . "->" . $f['name'] . " ?>" ?></td>
                <?php endforeach; ?>

                <td><?php echo "<?php echo $" . $model . "->created_at ?>" ?></td>
                <td><?php echo "<?php echo $" . $model . "->updated_at ?>" ?></td>

                <td>
<a href="<?php echo "<?php echo URL::site('" . ($set_dir ? $dir.'/':'') . "$model/edit/" . "' . $$model ->id) ?>" ?>">Edit</a>
<a href="<?php echo "<?php echo URL::site('" . ($set_dir ? $dir.'/':'') . "$model/delete/" . "' . $$model ->id) ?>" ?>"
   onclick="return confirm('Delete ?');">Delete</a>
                </td>
            </tr>
            <?php echo "<?php endforeach; ?>" ?>
        </tbody>
    </table>


    <div><?php echo '<?php echo $pagination->render() ?>' ?></div>

</div>
        <?php echo "<?php echo form::close() ?>" ?>

<?php echo "<?php endif; ?>" ?>

<script LANGUAGE="JavaScript" type="text/javascript">

    function doAction(obj, action, conf, messege)
    {
        obj.form.elements['action'].value = action;

        if (conf)
        {
            if (confirm(messege))
                obj.form.submit();
        }
        else
            obj.form.submit();
    }

    $(function(){
        $('#<?php echo $model ?>_check_all').click(function(){
            if ($(this).attr('checked'))
                $('input.checkbox').attr('checked', 'checked');
            else
                $('input.checkbox').removeAttr('checked');
        });

        $('input.checkbox').click(function(){
            if (! $(this).attr('checked') && $('<?php echo $model ?>_check_all').attr('checked'))
                $('#<?php echo $model ?>_check_all').removeAttr('checked');
        });
    });
</script>